
package cliente;

import DatagramPlusPlus.DatagramPlusPlusSocket;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;

/**
 *
 * @author rafael
 */
public class MainCliente {

    private static DatagramPlusPlusSocket socket;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
            throws UnknownHostException, SocketException, FileNotFoundException, IOException {

        System.out.println("Usage: ip\nporta\ncaminhoFicheiro");

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader stdin = new BufferedReader(isr);

        String ipName = stdin.readLine();
        String porta = stdin.readLine();
        String file = stdin.readLine();

        InetAddress ip = InetAddress.getByName(ipName);
        int port = Integer.valueOf(porta);
        socket = new DatagramPlusPlusSocket(ip, port);

        OutputStream out = socket.getOutputStream();

        File f = new File(file);
        InputStream in = new FileInputStream(f);
        while(in.available()>0) {
            byte[] b = new byte[1034];
            in.read(b);
            out.write(b);
        }
    }
}
